﻿
// 获取当前日期时间
var now = new Date();
var year = now.getFullYear();
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var day = ("0" + now.getDate()).slice(-2);
var hours = ("0" + now.getHours()).slice(-2);
var minutes = ("0" + now.getMinutes()).slice(-2);
//var seconds = ("0" + now.getSeconds()).slice(-2);
var serialNumber = "PX" + year + month + day + hours + minutes;
var inputElement = document.getElementById('WorkOrderCode');
inputElement.value = serialNumber;

var obj1 = {

    "createdBy": "",
    "isDeleted": false,
    "workOrderCode": "",
    "customer": "",
    "productionNumber": "",
    "orderCode": "",
    "priority": "",
    "workOrderSart": "",
    "currenProcess": "",
    "notes": "",
    "finishedProduct": "",
    "finishedProductCode": "",
    "specification": "",
    "size": "",
    "unit": "",
    "workShop": "",
    "production": "",
    "singleNumber": "",
    "startDate": "",
    "endDate": "",
    "processRoute": ""
}

layui.use(['table', 'dropdown', 'layer', 'form'], function () {
    var table = layui.table;
    var dropdown = layui.dropdown;
    var layer = layui.layer;
    var form = layui.form;
    var laypage = layui.laypage;


    //添加工单信息
    form.on('submit(formSubmit)', function (data) {
        var field = data.field;
        var checkStatus = table.checkStatus('allocWorkOrder');
        field.allocationProdutesList = checkStatus.data.map(function (item) {
            return item;
        });
        console.log(field);//field.products
      
        obj1.createdBy = ""
        obj1.workOrderCode = $("#WorkOrderCode").val()
        obj1.customer = $("#Customer").val()
        obj1.productionNumber = $("#ProductionNumber").val()
        obj1.orderCode = $("#OrderCode").val()
        obj1.priority = $("[name='Priority']:checked").val()
        obj1.workOrderSart = "待下发"
        obj1.currenProcess = ""
        obj1.notes = $("#Notes").val()
        obj1.finishedProduct = $("#FinishedProduct").val()
        obj1.finishedProductCode = $("#FinishedProductCode").val()
        obj1.specification = $("#Specification").val()
        obj1.size = $("#Size").val()
        obj1.unit = $("#Unit").val()
        obj1.workShop = $("#WorkShop").val()
        obj1.production = $("#Production").val()
        obj1.singleNumber = ""
        obj1.startDate = $("#StartDate").val()
        obj1.endDate = $("#EndDate").val()
        obj1.processRoute = $("#ProcessRoute").val()
       
      
       
        console.log(obj1)
        // 显示填写结果，仅作演示用
        $.ajax({
            url: '../Manufacture/WorkOrderAdd',
            type: 'post',
            data: {
                field: obj1, token: localStorage.getItem("token")
            },
            success: function (res) {
                var res = JSON.parse(res)
                console.log(field);
                console.log(res);
                if (res.Code > 0) {
                    layer.alert("添加成功");
                    //location.href = '/Process/ShowProcess'
                } else {
                    layer.alert("添加失败");
                }
            }
        });

        return false; // 阻止默认 form 跳转
    });

})
